﻿using System;

using System.Collections.Generic;



public class Student

{

    public string Id { get; set; }

    public string Name { get; set; }

    public int Age { get; set; }



    public Student(string id, string name, int age)

    {

        Id = id;

        Name = name;

        Age = age;

    }



    public override string ToString()

    {

        return $"学号：{Id}，姓名：{Name}，年龄：{Age}";

    }

}



public class StudentManager

{

    private List<Student> studentList = new List<Student>();



    public void AddStudent(Student student) => studentList.Add(student);



    public bool UpdateStudent(string id, Student newStudent)

    {

        for (int i = 0; i < studentList.Count; i++)

            if (studentList[i].Id == id)

            {

                studentList[i] = newStudent;

                return true;

            }

        return false;

    }



    public bool RemoveStudent(Student student) => studentList.Remove(student);



    public Student QueryStudent(string id)

    {

        foreach (var student in studentList)

            if (student.Id == id) return student;

        return null;

    }



    public void TraverseStudents()

    {

        foreach (var student in studentList)

            Console.WriteLine(student);

    }

}



class Program

{

    static void Main(string[] args)

    {

        StudentManager manager = new StudentManager();

        manager.AddStudent(new Student("1001", "张三", 18));

        manager.AddStudent(new Student("1002", "李四", 19));



        Console.WriteLine("所有学生：");

        manager.TraverseStudents();



        Student stu = manager.QueryStudent("1001");

        Console.WriteLine("\n查询到的学生：" + stu);



        bool isUpdated = manager.UpdateStudent("1002", new Student("1002", "李四新", 20));

        Console.WriteLine("\n修改结果：" + (isUpdated ? "成功" : "失败"));

        Console.WriteLine("修改后所有学生：");

        manager.TraverseStudents();



        bool isRemoved = manager.RemoveStudent(stu);

        Console.WriteLine("\n删除结果：" + (isRemoved ? "成功" : "失败"));

        Console.WriteLine("删除后所有学生：");

        manager.TraverseStudents();

    }

}